package cn.itcast.order.service;

import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import cn.itcast.order.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private RestTemplate restTemplate;

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);

        //2. 根据order 中userId --》发送导 user模块来进行查询
        Long userId = order.getUserId();
        String url = "http://127.0.0.1:8081/user/"+userId;
        User findUser = restTemplate.getForObject(url, User.class);
        order.setUser(findUser);

        // 4.返回
        return order;
    }
}
